﻿Imports Publics
Module ModuleHeThong
    Public Const SuperAdmin As String = "SuperAdmin"
#Region "Lấy thông tin phím tắt"
    ''' <summary>
    ''' Lấy thông tin phím tắt cơ bản: 
    ''' Thêm, sửa, xóa, nạp lại, xuất dữ liệu, trợ giúp, đóng
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetLabelPhimTatCoBan(ByVal TenDanhMuc As String, ByVal Them As Boolean, ByVal Sua As Boolean, ByVal Xoa As Boolean) As String
        'Dim str As String = "Danh mục " & TenDanhMuc 'Bỏ cái này đi. Caption form có tên danh mục rồi cho cái này làm cái quái j nữa
        Dim str As String = "Phím tắt "
        If TenDanhMuc = "sản phẩm" Then
            str &= IIf(Them, GetStrKey(kThem), "") + IIf(Sua, GetStrKey(kSua), "") + IIf(Them, GetStrKey(kCopy), "") + IIf(Xoa, GetStrKey(kXoa), "") + _
                   GetStrKey(kLamTuoi) + GetStrKey(kXuat) + GetStrKey(kTroGiup) + GetStrKey(kThoat)
            'Bỏ: GetStrKey(kTimKiem) + 
        Else
            str &= IIf(Them, GetStrKey(kThem), "") + IIf(Sua, GetStrKey(kSua), "") + IIf(Xoa, GetStrKey(kXoa), "") + _
                   GetStrKey(kLamTuoi) + GetStrKey(kXuat) + GetStrKey(kTroGiup) + GetStrKey(kThoat)

        End If
        Return str
    End Function

    ''' <summary>
    ''' Lấy thông tin phím tắt cơ bản form cập nhật sản phẩm: 
    ''' Ghi và thêm, ghi và đóng, xóa, trợ giúp, đóng
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetLabelPhimTatCoBanCapNhatDanhMucSanPhamLapRap() As String
        Return GetStrKey(kGhiVaThem) + GetStrKey(kGhiVaDong) + GetStrKey(kXoa) + GetStrKey(kTroGiup) + GetStrKey(kThoat)
    End Function

    ''' <summary>
    ''' Lấy thông tin phím tắt cơ bản form cập nhật sản phẩm: 
    ''' Ghi và thêm, ghi và đóng, trợ giúp, đóng
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetLabelPhimTatCoBanCapNhatDanhMucCoGhiVaThem() As String
        Return GetStrKey(kGhiVaThem) + GetStrKey(kGhiVaDong) + GetStrKey(kTroGiup) + GetStrKey(kThoat)
    End Function

    ''' <summary>
    ''' Lấy thông tin phím tắt cơ bản form cập nhật: 
    ''' Ghi và đóng, trợ giúp, đóng
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetLabelPhimTatCoBanCapNhatDanhMuc() As String
        Return GetStrKey(kGhiVaDong) + GetStrKey(kTroGiup) + GetStrKey(kThoat)
    End Function

    ''' <summary>
    ''' Lấy thông tin phím tắt cơ bản form cập nhật: 
    ''' Ghi và thêm, Ghi và đóng, trợ giúp, đóng
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetLabelPhimTatCoBanCapNhatDonDat() As String
        Return GetStrKey(kGhiVaThem) + GetStrKey(kGhiVaDong) + GetStrKey(kTroGiup) + GetStrKey(kThoat)
    End Function

#End Region

    Public Function iGetAllDivisionChild(ByVal IDTK As String) As Collection
        Dim iCollection As New Collection
        If Not IDTK.Equals(Nothing) Or IDTK.Trim = "" Then
            iCollection = New Collection
            iCollection.Add(IDTK, CStr(IDTK))
            For Each iPart As String In (From ds In dbTV.DM_DonVis _
                                          Where ds.InUsed AndAlso ds.ParentID.Equals(IDTK) _
                                          Select ds.ID)
                Dim iSubCollection As Collection = iGetAllDivisionChild(iPart)
                For i As Integer = 1 To iSubCollection.Count
                    iCollection.Add(iSubCollection.Item(i), CStr(iSubCollection.Item(i)))
                Next
            Next
        End If
        iGetAllDivisionChild = iCollection
    End Function
    Public Function GetStrKey(ByVal Phim As clsPhimTat) As String
        Try
            Dim strCaptionKey As String = ""
            Select Case Phim.MaNut
                Case pIdThem
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnAddNewCaption + "]"
                Case pIdSua
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnEditCaption + "]"
                Case pIdXoa
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnDeleteCaption + "]"
                Case pIdChon
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnAcceptCaption + "]"
                Case pIdXuat
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnExportDataCaption + "]"
                Case pIdThoat
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnCloseCaption + "]"
                Case pIdTimKiem
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnSearchCaption + "]"
                Case pIdTimTiep

                Case pIdGhiVaDong
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnSaveAndCloseCaption + "]"
                Case pIdGhiVaThem
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnSaveAndAddCaption + "]"
                Case pIdIn
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnPrintCaption + "]"
                Case pIdTroGiup
                    strCaptionKey = " [" + Trim(Phim.TenNut) + ": " + _
                BtnHelpCaption + "]"
            End Select
            Return strCaptionKey
        Catch ex As Exception
            MsgErr(ex.Message)
            Return Nothing
        End Try
    End Function
    Public Function GetInfoKey(ByVal maPhim As String) As clsPhimTat
        Dim Key As New clsPhimTat
        Try
            Key = (From db In vlstPhimTat Where db.MaNut = maPhim Select db).FirstOrDefault
        Catch ex As Exception
            MsgErr(ex.Message)
        End Try
        Return Key
    End Function
    'Thông tin phím tắt
    Public kThem As clsPhimTat = GetInfoKey(pIdThem)
    Public kSua As clsPhimTat = GetInfoKey(pIdSua)
    Public kXoa As clsPhimTat = GetInfoKey(pIdXoa)
    Public kChon As clsPhimTat = GetInfoKey(pIdChon)
    Public kXuat As clsPhimTat = GetInfoKey(pIdXuat)
    Public kThoat As clsPhimTat = GetInfoKey(pIdThoat)
    Public kTimKiem As clsPhimTat = GetInfoKey(pIdTimKiem)
    Public kTimTiep As clsPhimTat = GetInfoKey(pIdTimTiep)
    Public kGhiVaDong As clsPhimTat = GetInfoKey(pIdGhiVaDong)
    Public kGhiVaThem As clsPhimTat = GetInfoKey(pIdGhiVaThem)
    Public kIn As clsPhimTat = GetInfoKey(pIdIn)
    Public kLamTuoi As clsPhimTat = GetInfoKey(pIdLamTuoi)
    Public kTroGiup As clsPhimTat = GetInfoKey(pIdTroGiup)
    Public kCopy As clsPhimTat = GetInfoKey(pIdCopy)
End Module
